/**
 *
 */
package com.jinglu.cloud.security.manage;

import cn.hutool.core.collection.CollectionUtil;
import com.jinglu.cloud.security.model.Permission;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.access.ConfigAttribute;
import org.springframework.security.access.SecurityConfig;
import org.springframework.stereotype.Component;

import java.util.*;

/**
 * 描述:  .<br>
 *
 * @author zhaotengfei
 * @date 2019年11月29日
 */
@Component
public class DefaultPermissionManager implements PermissionManager {


    private Logger logger = LoggerFactory.getLogger(getClass());

    @Override
    public Map<String, Collection<ConfigAttribute>> loadResourceDefine() {
        List<Permission>  permissions = new ArrayList<>();
        return convert(permissions);
    }

    Map<String,Collection<ConfigAttribute>> convert(List<Permission> permissions){
        //logger.info("获取的权限集合==========" + JSON.toJSONString(permissions));
        Map<String, Collection<ConfigAttribute>> newData = new HashMap<>();
        if(CollectionUtil.isNotEmpty(permissions)){
            for (Permission permission : permissions) {
                List<ConfigAttribute> newValue = new ArrayList<>();
                newValue.add(new SecurityConfig(permission.getPermissionUrl()));
                newData.put(permission.getPermissionUrl(),newValue);
            }
        }

       return newData;
    }
}
